$(function () {
    let id = localStorage.getItem("messageId");
    selectMessageById(id);
})

//查询一条数据库
function selectMessageById(id) {
    $.ajax({
        data: {id: id},
        url: '/back/message/updateMessage',
        dataType: 'json',
        type: 'get',
        success: function (data) {
            setData(data.messageModel);
        }
    })
}

function setData(data) {
    $("#name").val(data.name);
    $("#email").val(data.email);
    $("#content").val(data.content);
}


//更新数据===================================================
function updateMessage() {
    let messageid = localStorage.getItem("messageId");
    updateMessageById(messageid);
}

function updateMessageById(id) {
    let data = {
        id:id,
        name:$("#name").val(),
        email:$("#email").val(),
        content:$("#content").val(),
    };
    $.ajax({
        data: data,
        url:'/back/message/updateMessage',
        dataType: 'json',
        type: 'post',
        success:function (data) {
            if (data.result==1){
                alert("更新成功");
            }else {
                alert("更新失败");
            };
        }
    });

}

//返回上一页面。。。。。。。。
function back() {
    $("#right").load("/back/html/message/messageManage.html");
}
